<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>执行查询</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.pg-query-params.html">pg_query_params</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pg-result-error-field.html">pg_result_error_field</a></div>
 <div class="up"><a href="ref.pgsql.html">PostgreSQL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.pg-query" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">pg_query</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">pg_query</span> &mdash; <span class="dc-title">执行查询</span></p>

   </div>
   <div class="refsect1 unknown-seealsp" id="refsect1-function.pg-query-unknown-seealsp">
    <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="type">resource</span> <span class="methodname"><strong>pg_query</strong></span>
       ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span>
      , <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>
      )</div>

    <p class="para rdfs-comment">
     <span class="function"><strong>pg_query()</strong></span>
     在查询可以执行时返回查询结果资源号。如果查询失败或者提供的连接号无效则返回
     <strong><code>FALSE</code></strong>。如果连接号有效，则可以用 <span class="function"><a href="function.pg-last-error.html" class="function">pg_last_error()</a></span>
     函数来提取详细的错误信息。<span class="function"><strong>pg_query()</strong></span>
     发送一条 SQL 语句到 <em><code class="parameter">connection</code></em>
     资源指定的 PostgreSQL 数据库。<em><code class="parameter">connection</code></em>
     必须是由 <span class="function"><a href="function.pg-connect.html" class="function">pg_connect()</a></span> 或 <span class="function"><a href="function.pg-pconnect.html" class="function">pg_pconnect()</a></span>
     返回的合法连接号。本函数返回值是一个其它 PostgreSQL 函数例如
     <span class="function"><a href="function.pg-fetch-array.html" class="function">pg_fetch_array()</a></span> 可以用来访问查询结果的查询结果资源号。
     <blockquote class="note"><p><strong class="note">Note</strong>: 
      <span class="simpara">
       <em><code class="parameter">connection</code></em> 是 <span class="function"><strong>pg_query()</strong></span>
       中的可选参数。如果没有指定
       <em><code class="parameter">connection</code></em>，则使用默认连接。默认连接是
       <span class="function"><a href="function.pg-connect.html" class="function">pg_connect()</a></span> 或 <span class="function"><a href="function.pg-pconnect.html" class="function">pg_pconnect()</a></span>
       所打开的最后一个连接。
      </span>
      <span class="simpara">
       尽管 <em><code class="parameter">connection</code></em>
       参数可以省略，但不推荐这样做。因为这样可能会导致很难发现脚本中的错误。
      </span>
     </p></blockquote>
    </p>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <p class="para">
      本函数以前的名字为 <em>pg_exec()</em>。<em>pg_exec()</em>
      函数为了兼容性的原因仍然可以使用，但是鼓励用户使用新的名字。
     </p>
    </p></blockquote>
    <p class="para">
     参见 <span class="function"><a href="function.pg-connect.html" class="function">pg_connect()</a></span>，<span class="function"><a href="function.pg-pconnect.html" class="function">pg_pconnect()</a></span>，<span class="function"><a href="function.pg-fetch-array.html" class="function">pg_fetch_array()</a></span>，<span class="function"><a href="function.pg-fetch-object.html" class="function">pg_fetch_object()</a></span>，<span class="function"><a href="function.pg-num-rows.html" class="function">pg_num_rows()</a></span>
     和 <span class="function"><a href="function.pg-affected-rows.html" class="function">pg_affected_rows()</a></span>。
    </p>
   </div>

  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.pg-query-params.html">pg_query_params</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pg-result-error-field.html">pg_result_error_field</a></div>
 <div class="up"><a href="ref.pgsql.html">PostgreSQL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
